#include <iostream>
using namespace std;

int count=0;

template <class T>
void permutations(T list[],int k,int m,T v[],int &count,T b[],int n);

template <class T>
T factorial(T n) {
    int fn=1;
    for (int i=n;i>=1;i--) {
        fn*=i;
    }
    return fn;
}

int main() {
    int n;
    cin >> n;
    int* a = new int(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int* v = new int(factorial(n));
    int* b = new int(n);
    permutations(a,0,n-1,v,count,b,n);
    int sumv = v[0];
    for (int i = 1; i < factorial(n); i++) {
        sumv = (sumv|v[i]);
    }
    cout << sumv;
}

template <class T>
void permutations(T list[],int k,int m,T v[],int &count,T b[],int n) {
    if (k==m) {
        copy(list,list+m+1,b);
        v[count]=0;
        for (int i=0;i<n;i++) {
            v[count]+=(i+1)^b[i];
        }
        count++;
    }
    else for (int i=k;i<=m;i++) {
        swap(list[k],list[i]);
        permutations(list,k+1,m,v,count,b,n);
        swap(list[k],list[i]);
    }
}